package cm.day12;


class MyThead1 extends Thread {
    static int sum = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                try {
                    if (sum < 100) {

                            Thread.sleep(100);
                            sum++;
                            System.out.println(getName() + sum + "张票");
                        }else {
                        break;

                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}


public class Test2 {
    public static void main(String[] args) {
        MyThead1 my1 = new MyThead1();
        MyThead1 my2 = new MyThead1();
        MyThead1 my3 = new MyThead1();
        my1.setName("A");
        my2.setName("B");
        my3.setName("C");
        my1.start();
        my2.start();
        my3.start();
    }
}
